package cac.common;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class SqlUtil {

    private static Pattern UNDERLINE_PATTERN = Pattern.compile("_([a-z])");

    public static void main(String[] args) {

        String [] arr = {//MS_TASK_PACKAGE_ID
                "PRODUCT_CODE",
                "PRODUCT_NAME",
                "STATE",
                "A_STATE",
                "CREATED_BY",
                "CREATION_DATE",
                "LAST_UPDATED_BY",
                "LAST_UPDATE_DATE",
                "LAST_UPDATE_IP",
                "VERSION",
                };
        for(int i = 0;i< arr.length;i++){
            System.out.println("<result property= \""+ change(arr[i].toLowerCase())+"\" "+"column=\"" +arr[i].toLowerCase()+"\" jdbcType=\""+""+"\"/>");
        }
    }

    public static String change(String arr){
        Matcher matcher = UNDERLINE_PATTERN.matcher(arr);
        StringBuffer sb = new StringBuffer(arr);
        if(matcher.find()){
            sb = new StringBuffer();
            matcher.appendReplacement(sb,matcher.group(1).toUpperCase());
            matcher.appendTail(sb);
        } else {
            return sb.toString().replaceAll("_","");
        }
        return change(sb.toString());
    }
}
